const steven = {
  name: "Steven",
  phoneBattery: 70,
  charge: function (level1, level2) {
    this.phoneBattery = level1 + level2;
  },
};

const backy = {
  name: "Backy",
  phoneBattery: 30,
};

steven.charge(40, 40);
console.log(steven.phoneBattery);

// call
steven.charge.call(backy, 30, 30);
console.log(backy.phoneBattery);

// apply
steven.charge.apply(backy, [40, 40]);
console.log(backy.phoneBattery);

// bind
const charge = steven.charge.bind(backy);
charge(50, 50);
console.log(backy.phoneBattery);

Function.prototype.bindFn = function () {
  let args = Array.prototype.slice.call(arguments);
  let obj = args.shift();
  console.log(obj);
  let self = this;
  console.log(self);
  return function () {
    return self.apply(obj, argumets);
  };
};

// bind of test
const bindFn = steven.charge.bindFn(backy);
bindFn(60, 60);
console.log(backy.phoneBattery);
